package com.wnx.db;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import com.wnx.entity.Goods;
import com.wnx.entity.Users;
import com.wnx.util.HibernateUtil;

public class BuyDao {
	public BuyDao(){
		
	}
	
	public List getGoodsById(int id){
		Session session = HibernateUtil.getSession();
		Transaction transaction = session.beginTransaction();
		String hql ="from Goods where id = ? ";
		Query<Goods> query = session.createQuery(hql,Goods.class);
		query.setParameter(0, id);
		List<Goods> goods = query.list();
		transaction.commit();
        session.close();
		return goods;
	}
	public Goods UpdateclickById(int id){
		Goods goods = new Goods();
		Session session = HibernateUtil.getSession();
		Transaction transaction = session.beginTransaction();
		String hql ="update Goods set click=click+1 where id=?";
		Query query = session.createQuery(hql);
		query.setParameter(0, id);
		query.executeUpdate();
		transaction.commit();
        session.close();
		return goods;
		
	}
}
